<?php
    require_once 'simple_html_dom.php';
    function getCategory($path){
    	
    ini_set('default_socket_timeout', 120);
    	
 	// create DOM from URL of file
 	$html  = file_get_html($path);
    // get data html
    $ddmcc_container = $html->find("div[id=ddmcc_container]", 0);
    $li = $ddmcc_container->find("li");
    
    $strFile = "";
    $result = "Result : ".sizeof($li)." Category<br/>";
    
    $tmp = 0; // TODO : mock object to break data
 	foreach ($li as $item) {
 	    $a = $item->find("a");
 		$a = $a[0];
 		
 		$href = $a->getAttribute("href");
 		
 		$strFile = $strFile.$a->innertext.",".$href."\n";
 		$result = $result."<input type='hidden' value='".$href."' class='hdCate' />";
 		
 		// TODO : mock code block
 		$tmp++;
 		if($tmp > 1) break;
 		
 	}
 	$file = fopen("category.txt",'a');
 	fwrite($file,$strFile);
 	fclose($file);
 	
 	echo $result;
 }
 
 getCategory($_POST['url']);
 
?>